var app = getApp()
Page({ 
  data: { 
    doctorId:'',
    doctors: [],
    keyword:'',
  }, 
  onLoad: function (options) {
      this.getDoctorList()
  },  
  onPullDownRefresh: function () { 
    this.getDoctorList()
    wx.showToast({
      title: '刷新成功',
      icon: 'success',
      duration: 1000
    })
  },  
  inputKeyword: function(e){
    this.setData({
      'keyword': e.detail.value
    })
  },
  getDoctorList: function() {
    var _this = this; 
    wx.request({ 
      url: app.globalData.doctor_list_url,
      data: {keyword:_this.data.keyword},
      method: 'GET', 
      success: function (res) {
        var resultData = res.data;
        if(resultData.errno == 0){ 
          _this.setData({doctors: resultData.data})   
        }
      },
      fail: function () {
        setTimeout(function () {
          wx.showToast({
            title: "加载失败"
          })
        }, 100)
      }
    })

  },
  liuyan:function(event) {  
    var loginUserId = wx.getStorageSync('LOGINUSER_ID') || '';
    if(loginUserId == ''){
      wx.redirectTo({
        url: '../index/index'
      })
    }else{
      wx.navigateTo({
        url: '../message-center/message-center?doctorId=' +  event.currentTarget.dataset.id
      })
    }
  },
  guahao: function(event) { 
    var loginUserId = wx.getStorageSync('LOGINUSER_ID') || '';
    if(loginUserId == ''){
      wx.redirectTo({
        url: '../index/index'
      })
    }else{
      wx.request({ 
        url: app.globalData.appointment_add_url,
        data: {userId:loginUserId,doctorId:event.currentTarget.dataset.id },
        method: 'POST', 
        success: function (res) {
          var resultData = res.data;
          if(resultData.errno == 0){
             app.showModel("预约结果",resultData.message)
          }
        },
        fail: function () {
          setTimeout(function () {
            wx.showToast({
              title: "加载失败"
            })
          }, 100)
        }
      })
    } 
  },
  gotoDetail: function(event) { 
    var id = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../doctor-detail/doctor-detail?id=' + id
    })
  },

})